import java.util.Scanner;


public class SortNumbers {
// simple sorting for double numbers
	public static void sort(double[] nums){
	for (int i=0; i<nums.length; i++){
		int min = i;
		for(int j = i; j<nums.length; j++){
			if (nums[j]<nums[min]) min=j;
		}
		double tmp;
		tmp = nums[i];
		nums[i]=nums[min];
		nums[min]=tmp;
	}
}
public static void main(String[] args){
	// simple test: sort 100 numbers,
	// read from input the number given by the user,
	// show between which two numbers this given one is.
	
	double[] nums = new double[100];
	int i;
	for (i=0; i<=nums.length-1; i++)
		nums[i] = Math.random() * 100;
	sort(nums);
	// numbers sorted
	// reading the input number:
	Scanner our_string = new Scanner(System.in);
	System.out.println("Please, input a number between " + nums[0] + " and " + nums[nums.length-1] );
	String nString = our_string.nextLine();
	double n_input;
	n_input = Double.parseDouble(nString);
	System.out.println("you have input the number "+n_input);
	// number from user is read
	//now looking for closest two numbers in our array
	if (n_input<nums[0] || n_input>nums[nums.length-1]) 
		System.out.println("input number is out of our array");
		else {
			for( i=0; i<=nums.length-1; i++){
				if (n_input>=nums[i] && n_input<=nums[i+1]){
					System.out.format("your number is between elements  number %d and number %d\n", i, i+1);
					System.out.format("which are %f and %f\n", nums[i], nums[i+1]);
					break;
				}
			}
		}
		
	}
	
}

